<?php
include("include/config.inc.php");
if(!isset($_SESSION['s_activIds']))
{
	header("Location:checkLogin.php");
}
else
{
  $userId = ($_SESSION['s_activIds']);
  $docArray = array();
  $i=0;
  $selectDoc = "SELECT userdoc.userId,userdoc.uploadFile,user.company,DATE_FORMAT(userdoc.uploadDateTime,'%d-%m-20%y %h:%i:%s') AS uploadDateTime
                  FROM userdoc
             LEFT JOIN user ON user.userId = userdoc.uploadedBy
                 WHERE userdoc.userId = ".$userId."";
  if($_GET['contractId'] > 0)
  {
    $selectDoc .= " AND userdoc.contractId = ".$_GET['contractId']."";
  }                   
  if($_GET['invoiceId'] > 0)
  {
    $selectDoc .= " AND userdoc.invoiceId = ".$_GET['invoiceId']."";
  }                   
  $selectDocRes = mysql_query($selectDoc);
  while($docRow = mysql_fetch_array($selectDocRes))
  {
  	$docArray[$i]['userId'] 	      = $docRow['userId'];
    $docArray[$i]['uploadFile']     = $docRow['uploadFile'];
    $docArray[$i]['company']        = $docRow['company'];
    $docArray[$i]['uploadDateTime'] = $docRow['uploadDateTime'];
    $i++;
  }
  
  include("bottom.php");
  $smarty->assign("docArray",$docArray);
  $smarty->display("getDocumentData.tpl");
}
?>